home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH06 / PGM6_6.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-10-10  |  2.1 KB  |  118 lines

  1. ; String Instructions
  2.  
  3.         .386            ;So we can use extended registers
  4.         option    segment:use16    ; and addressing modes.
  5.  
  6. dseg        segment    para public 'data'
  7.  
  8. String1        byte    "String",0
  9. String2        byte    7 dup (?)
  10.  
  11. Array1        word    1, 2, 3, 4, 5, 6, 7, 8
  12. Array2        word    8 dup (?)
  13.  
  14. dseg        ends
  15.  
  16. cseg        segment    para public 'code'
  17.         assume    cs:cseg, ds:dseg
  18.  
  19. Main        proc
  20.         mov    ax, dseg
  21.         mov    ds, ax
  22.         mov    es, ax
  23.  
  24.  
  25. ; The string instructions let you easily copy data from one array to
  26. ; another.  If the direction flag is clear, the movsb instruction
  27. ; does the equivalent of the following:
  28. ;
  29. ;    mov es:[di], ds:[si]
  30. ;    inc    si
  31. ;    inc    di
  32. ;
  33. ; The following code copies the seven bytes from String1 to String2:
  34.  
  35.         cld            ;Required if you want to INC SI/DI
  36.  
  37.         lea    si, String1
  38.         lea    di, String2
  39.  
  40.         movsb            ;String2[0] := String1[0]
  41.         movsb            ;String2[1] := String1[1]
  42.         movsb            ;String2[2] := String1[2]
  43.         movsb            ;String2[3] := String1[3]
  44.         movsb            ;String2[4] := String1[4]
  45.         movsb            ;String2[5] := String1[5]
  46.         movsb            ;String2[6] := String1[6]
  47.  
  48. ; The following code sequence demonstrates how you can use the LODSW and
  49. ; STOWS instructions to manipulate array elements during the transfer.
  50. ; The following code computes
  51. ;
  52. ;    Array2[0] := Array1[0]
  53. ;    Array2[1] := Array1[0] * Array1[1]
  54. ;    Array2[2] := Array1[0] * Array1[1] * Array1[2]
  55. ;    etc.
  56. ;
  57. ; Of course, it would be far more efficient to put the following code
  58. ; into a loop, but that will come later.
  59.  
  60.         lea    si, Array1
  61.         lea    di, Array2
  62.  
  63.         lodsw
  64.         mov    dx, ax
  65.         stosw
  66.  
  67.         lodsw
  68.         imul    ax, dx
  69.         mov    dx, ax
  70.         stosw
  71.  
  72.         lodsw
  73.         imul    ax, dx
  74.         mov    dx, ax
  75.         stosw
  76.  
  77.         lodsw
  78.         imul    ax, dx
  79.         mov    dx, ax
  80.         stosw
  81.  
  82.         lodsw
  83.         imul    ax, dx
  84.         mov    dx, ax
  85.         stosw
  86.  
  87.         lodsw
  88.         imul    ax, dx
  89.         mov    dx, ax
  90.         stosw
  91.  
  92.         lodsw
  93.         imul    ax, dx
  94.         mov    dx, ax
  95.         stosw
  96.  
  97.         lodsw
  98.         imul    ax, dx
  99.         mov    dx, ax
  100.         stosw
  101.  
  102.  
  103.  
  104. Quit:        mov    ah, 4ch            ;DOS opcode to quit program.
  105.         int    21h            ;Call DOS.
  106. Main        endp
  107.  
  108. cseg        ends
  109.  
  110. sseg        segment    para stack 'stack'
  111. stk        byte    1024 dup ("stack   ")
  112. sseg        ends
  113.  
  114. zzzzzzseg    segment    para public 'zzzzzz'
  115. LastBytes    byte    16 dup (?)
  116. zzzzzzseg    ends
  117.         end    Main
  118.